/* logic.h : include common headers and declarations of all logic components */
#pragma once

#include <stdio.h>
#include <string>
#include <vector>

class Session;
class Player;
class Building;
class Resource;
class BType;

using namespace std;
enum { NoPlayer = -1};

//c:\code\monopoly\logic\logic.cpp(24) : warning C4996: 'strcpy' was declared deprecated
#pragma warning(disable:4996)
//warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
#pragma warning(disable:4267)

//------------GlobalVariables----------
extern Session * mainSession;

//-------------Session-----------------
/*Class: Session
  Semantics: contain all session params
  * begins game, 
  * add players, 
  * creates resource and building types*/
class Session
{
public:
    enum { NoPlayer = -1};
    Session ();
    ~Session ();
    // get:
    vector <Player> getPlayers() { return players; };
    vector <Building> getBuildings() { return buildings; };
	vector <Resource> getResources() { return resources; };
	vector <BType> getTypes() { return types; };
    int getTurnCounter () {return turnCounter;};
    Player * getCurrentPlayer() { return &players [currentPlayerId]; };
    // evaluate: 
	int totalOutcome( Player * player);
    void turn ();
    // public variables
	BType * defaultType;
    Resource * defaultResource;
    void createResources();
    void createBTypes();
private:
    int turnCounter;
    int currentPlayerId;
    vector <Player> players;
    vector <Building> buildings;
	vector <Resource> resources;
	vector <BType> types;
    friend Player;
};

//-------------Player--------------------
/*Class: Player
  Contains all player paremeters*/
class Player
{
public:
    enum { defaultMoney = 1000 };
    Player ();
    Player ( char *name, int rank);
    ~Player ();

    //get:
    char * getName() { return name; };
    int getMoney() { return money; };
    int getRank() { return rank; };
    int getIncome() { return income; };

    // building operations:
    vector <Building> getBuilding () { return buildings;};
    void addBuilding ( Building *b);
    void deleteBuilding ( Building *b);

    // money operations:
    void addMoney ( int sum) { money += sum;};
    void evaluateMoney () { money += income;};
    void evaluateIncome ();

private:
    int rank, money, income;
    char * name;
    vector <Building> buildings;
};

//-----------Bulding Type------------
// determines type of building
class BType
{
public:
    vector <Resource> cons;
    vector <int> consAmount;
    vector <Resource> prod;
    vector <int> prodAmount;
    char * typeName;
};

//-------------Building------------------
/*Class: Building
  Semantics: contain basic building
  which should be used for creating 
  any enterprise.*/
class Building
{
private:
    int price, productionPrice, income, owner;
    char * name;
    BType *type;
public:
    enum {DefaultIncome = 100};

    Building ();
    Building ( BType * type);
    Building ( char * name, int pr, int inc);
    ~Building () {};

    //get:
    int getPrice() { return price;};
    char * getName() { return name;};
    int getIncome () { return income;};
    int getOwner() { return owner;};
    vector <Resource> getConsRes() {return type->cons;};
    vector <Resource> getProdRes() {return type->prod;};
    vector <int> getConsAmount() {return type->consAmount;};
    vector <int> getProdAmount() {return type->prodAmount;};
    BType * getType () { return type; };
    
    //set:
    void setProductionPrice( int i) { productionPrice = i;};
    void setPrice ( int i) { price = i;};
    void setName ( char * n);
    void setIncome ();
    void setOwner( int i) { owner = i;};
    void setType ( BType * intype) { type = intype; };
    
    //eval:
    int evaluateConsumption();
};

//-------------Resource------------------
class Resource
{
private:
	char * name;
	int price;
public:
	Resource();
	Resource( char * str, int pr);
	~Resource(){};
	enum { defaultPrice = 5};
	int getPrice();
	void setPrice(int);
    char * getName() {return name;};
};
